<?php
/* --------------------------------------------------------------
   PropertiesContentView.inc.php 2012-02-14 tb@gambio
   Gambio GmbH
   http://www.gambio.de
   Copyright (c) 2011 Gambio GmbH
   Released under the GNU General Public License (Version 2)
   [http://www.gnu.org/licenses/gpl-2.0.html]
   --------------------------------------------------------------
*/

class PropertiesContentView extends ContentView
{
	function PropertiesContentView() 
	{
		$this->v_coo_properties_admin_control = MainFactory::create_object('PropertiesAdminControl');
	}
	
	function get_html($p_param)
	{
		$t_html_output = '';

		$c_properties_id = (int)$p_param['properties_id'];
		
		if($c_properties_id > 0)
		{
			# load properties data by optional given properties_id
			$t_properties_names_array_tmp = $this->v_coo_properties_admin_control->get_properties_full_struct($c_properties_id, false, false);
			$t_properties_names_array = $t_properties_names_array_tmp['PROPERTIES_LANGUAGE_ARRAY'];
			$t_sort_order = $t_properties_names_array_tmp['sort_order'];
			$t_properties_id = $t_properties_names_array_tmp['properties_id'];
			$t_properties_in_combis_count = $this->v_coo_properties_admin_control->get_properties_in_combis_count($c_properties_id);
		}
		else
		{
			# no properties_id given. use defaults and empty array for empty fields
			$t_properties_names_array = array();
			$t_sort_order = '1';
			$t_properties_id = '';
			$t_properties_in_combis_count = 0;
		}
		
		$t_languages_array = xtc_get_languages();
		$t_properties_names_fields_array = array();
		
		# merge language_array with (maybe empty) names_array
		for($i=0; $i<sizeof($t_languages_array); $i++)
		{
			$t_value = '';
			foreach($t_properties_names_array AS $t_properties_language_array_item){
				if($t_languages_array[$i]['id'] ==  $t_properties_language_array_item['language_id']){
					$t_properties_name = $t_properties_language_array_item['properties_name'];
					$t_properties_admin_name = $t_properties_language_array_item['properties_admin_name'];
				}
			}
			$t_properties_names_fields_array[] = array_merge(
																	$t_languages_array[$i],
																	array('properties_name' => $t_properties_name, 'properties_admin_name' => $t_properties_admin_name)
																);
		}
		
		# html build-data
		$t_content_data_array = array(
									'PROPERTIES_NAMES_FIELDS' => $t_properties_names_fields_array,
									'sort_order' => $t_sort_order,
									'properties_id' => $t_properties_id,
									'properties_in_combis_count' => $t_properties_in_combis_count
								);
		
		$this->set_content_data("properties_data", $t_content_data_array);
		
		$t_html_output = $this->build_html();
		return $t_html_output;
	}
}
?>